# This has two processes cooperating to increase r from 0 to 20.
# Note that in this example we have imported the multiprocessing
# module in a new way, so we don't need to prefix "multiprocssing."
# to its items.

from multiprocessing import *
import time

def F(r):
    # This increments r 10 times
    for i in range(0, 10):
        x = r.value
        y = x+1
        r.value = y
        print( "Process %d set r to %d" % (current_process().pid, r.value))
        time.sleep(0.05)  # to model steps that take longer

def main():
    r = RawValue("i", 0)
    p = Process(target=F, args = (r,))
    q = Process(target=F, args = (r,))
    p.start()
    q.start()

if __name__ == "__main__":
    main()
    input()

